﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Common.Utilities.Excel.Import
{
    /// <summary>
    /// 导入的Excel
    /// </summary>
    public class Excel
    {
        /// <summary>
        /// 工作簿集合
        /// </summary>
        public List<Worksheet> Worksheets { get; set; }

        /// <summary>
        /// 以DataSet表示的数据源
        /// </summary>
        public DataSet DataSet
        {
            get
            {
                DataSet ds = new DataSet();
                foreach (var worksheet in Worksheets)
                {
                    ds.Tables.Add(worksheet.DataTable);
                }
                return ds;
            }
        }

        /// <summary>
        /// 得到相应的工作簿
        /// </summary>
        /// <param name="sheetName">工作簿名称</param>
        /// <returns></returns>
        public Worksheet this[string sheetName]
        {
            get
            {
                if (Worksheets == null) return null;
                return Worksheets.FirstOrDefault(ws => ws.DataTableName.Equals(sheetName, StringComparison.InvariantCultureIgnoreCase));
            }
        }
    }
}
